home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Almathera Ten Pack 3: CDPD 3
/
Almathera Ten on Ten - Disc 3: CDPD3.iso
/
fish
/
676-700
/
681
/
term
/
source.lha
/
DialPanel.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-05-09
|
31KB
|
1,324 lines
/*
** $Id: DialPanel.c,v 1.8 92/05/08 20:50:02 olsen Sta Locker: olsen $
** $Revision: 1.8 $
** $Date: 92/05/08 20:50:02 $
**
** The dialing routine as called by the phonebook
**
** Copyright © 1990-1992 by Olaf `Olsen' Barthel & MXM
** All Rights Reserved
*/
#include "termGlobal.h"
/* Dimensions of the panel window. */
#define WIDTH 458
#define HEIGHT 95
/* Some layout assistance. */
#define GADGET_WIDTH (13 * 8)
#define GADGET_COUNT 4
#define GADGET_SPACE (GADGET_WIDTH + ((WIDTH - 20) - (GADGET_COUNT * GADGET_WIDTH)) / (GADGET_COUNT - 1))
/* Panel gadget IDs. */
enum { GAD_SKIP,GAD_REMOVE,GAD_ONLINE,GAD_ABORT };
UBYTE LineOffset[8] = { 20,28,36,0,50,58,0,72 };
/* CreateAllGadgets():
*
* Create all gadgets required by the dial panel.
*/
STATIC struct Gadget *
CreateAllGadgets(struct Gadget **GadgetArray,struct Gadget **GadgetList,APTR VisualInfo,UWORD TopEdge)
{
struct Gadget *Gadget;
struct NewGadget NewGadget;
UWORD Counter = 0;
memset(&NewGadget,0,sizeof(struct NewGadget));
if(Gadget = CreateContext(GadgetList))
{
NewGadget . ng_Height = 12;
NewGadget . ng_GadgetText = LocaleString(MSG_DIALPANEL_SKIP_GAD);
NewGadget . ng_Width = GADGET_WIDTH;
NewGadget . ng_TextAttr = &DefaultFont;
NewGadget . ng_VisualInfo = VisualInfo;
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_LeftEdge = 10;
NewGadget . ng_Flags = 0;
NewGadget . ng_TopEdge = HEIGHT - 3 - NewGadget . ng_Height;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_GLOBAL_REMOVE_GAD);
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_LeftEdge = NewGadget . ng_LeftEdge + GADGET_SPACE;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_DIALPANEL_GO_TO_ONLINE_GAD);
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_LeftEdge = NewGadget . ng_LeftEdge + GADGET_SPACE;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
TAG_DONE);
NewGadget . ng_GadgetText = LocaleString(MSG_GLOBAL_ABORT_GAD);
NewGadget . ng_GadgetID = Counter;
NewGadget . ng_LeftEdge = NewGadget . ng_LeftEdge + GADGET_SPACE;
GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
GT_Underscore, '_',
TAG_DONE);
}
return(Gadget);
}
/* PrintInfo(struct Window *SomeWindow,WORD X,WORD Y,BYTE *String,...):
*
* Print a string at a given position into the panel window.
*/
STATIC VOID __stdargs
PrintInfo(struct Window *SomeWindow,WORD Y,BYTE *String,...)
{
va_list VarArgs;
BYTE FgPen = SomeWindow -> RPort -> FgPen;
va_start(VarArgs,String);
VSPrintf(SharedBuffer,String,VarArgs);
va_end(VarArgs);
SetAPen(SomeWindow -> RPort,0);
RectFill(SomeWindow -> RPort,86,LineOffset[Y] - 6,78 + 360 - 1 - 3,LineOffset[Y] + 1);
SetAPen(SomeWindow -> RPort,FgPen);
Move(SomeWindow -> RPort,86,LineOffset[Y]);
Text(SomeWindow -> RPort,SharedBuffer,strlen(SharedBuffer));
}
STATIC VOID __regargs
PrintText(struct Window *Window,WORD Y,UBYTE *String)
{
Move(Window -> RPort,10,LineOffset[Y]);
Text(Window -> RPort,String,strlen(String));
}
/* DialPanel():
*
* This routine opens a small window in the middle of the
* console window and walks down the list of numbers to
* dial.
*/
BYTE
DialPanel()
{
STATIC WORD PositionX = -1,
PositionY = -1;
struct Gadget *GadgetList = NULL;
struct Gadget *GadgetArray[GADGET_COUNT];
struct Window *PanelWindow;
struct PhoneNode *DialNode;
BYTE Result = FALSE;
ChosenEntry = NULL;
BaudBuffer[0] = 0;
/* We are dialing. */
Status = STATUS_DIALING;
/* Create the gadgets. */
if(CreateAllGadgets(&GadgetArray[0],&GadgetList,VisualInfo,Screen -> WBorTop + Screen -> Font -> ta_YSize + 1))
{
if(PositionX == -1)
PositionX = (Screen -> Width - WIDTH) >> 1;
if(PositionY == -1)
PositionY = (Screen -> Height - HEIGHT) >> 1;
/* At last, open the window. */
if(PanelWindow = OpenWindowTags(NULL,
WA_Width, WIDTH - 1,
WA_Height, HEIGHT,
WA_Left, PositionX,
WA_Top, PositionY,
WA_Activate, TRUE,
WA_DragBar, TRUE,
WA_DepthGadget, TRUE,
WA_CloseGadget, TRUE,
WA_RMBTrap, TRUE,
WA_CustomScreen,Screen,
WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY | BUTTONIDCMP,
WA_Title, LocaleString(MSG_DIALPANEL_DIALING_TXT),
TAG_DONE))
{
struct IntuiMessage *Massage;
ULONG Class,Code;
struct Gadget *Gadget;
LONG RedialDelay = 0,DialTimeout,DialRetries,DialAttempt;
BYTE Dialing,Terminated = FALSE,BaudWasPending = FALSE;
UBYTE SomeBuffer[300],ExitString[80];
BYTE Pen,RunCount = 0;
UBYTE NumberBuffer[40], *NextNumber = NULL,
InitBuffer[80], *NextInit = NULL,
ExitBuffer[80], *NextExit = NULL,
PrefixBuffer[80], *NextPrefix = NULL;
ExitString[0] = 0;
/* Determine the colours to use for display. */
switch(Config . ColourMode)
{
case COLOUR_EIGHT: Pen = 7;
break;
case COLOUR_SIXTEEN: Pen = 15;
break;
default: Pen = 1;
break;
}
/* Make the current one the active one. */
PushWindow(PanelWindow);
/* Make a backup of the current configuration. */
CopyMem(&Config,&PrivateConfig,sizeof(struct Configuration));
/* Add the gadgets and refresh them. */
AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
GT_RefreshWindow(PanelWindow,NULL);
/* Print some information into the
* panel window.
*/
SetAPen(PanelWindow -> RPort,Pen);
DrawBevelBox(PanelWindow -> RPort,82,12,364,28,
GTBB_Recessed, TRUE,
GT_VisualInfo, VisualInfo,
TAG_DONE);
DrawBevelBox(PanelWindow -> RPort,82,42,364,20,
GTBB_Recessed, TRUE,
GT_VisualInfo, VisualInfo,
TAG_DONE);
DrawBevelBox(PanelWindow -> RPort,82,64,364,12,
GTBB_Recessed, TRUE,
GT_VisualInfo, VisualInfo,
TAG_DONE);
PrintText(PanelWindow,0,LocaleString(MSG_DIALPANEL_CALLING_TXT));
PrintText(PanelWindow,1,LocaleString(MSG_DIALPANEL_NUMBER_TXT));
PrintText(PanelWindow,2,LocaleString(MSG_DIALPANEL_NEXT_TXT));
PrintText(PanelWindow,4,LocaleString(MSG_DIALPANEL_TIMEOUT_TXT));
PrintText(PanelWindow,5,LocaleString(MSG_DIALPANEL_ATTEMPT_TXT));
PrintText(PanelWindow,7,LocaleString(MSG_DIALPANEL_MESSAGE_TXT));
/* Don't echo serial output. */
Quiet = TRUE;
/* Perform full sequence check. */
FullCheck = TRUE;
/* Reset the number of dial attempts. */
DialAttempt = 0;
/* Get the first dial list entry. */
DialNode = (struct PhoneNode *)DialList -> lh_Head;
/* The big dialing loop, implemented as a goto -> mark
* loop rather than one of those classical while .. do
* loops.
*/
Dial: Dialing = TRUE;
/* Reset the sequence scanner, the user may have skipped
* the previous dial attempt causing the modem to return
* `NO CARRIER'. To prevent the dialer from skipping the
* next dial entry as well as the previous we have to
* flush any data pending on the serial line.
*/
HandleSerial();
FlowInit();
FullCheck = TRUE;
/* Now for multiple phone numbers separated
* by `|' characters. If `NextNumber' happens
* to be zero, we will prepare to extract
* the first phone number from the list.
* In any other case we will try to obtain
* the next number.
*/
if(NextNumber)
{
NextNumber = ExtractString(NextNumber, NumberBuffer,TRUE);
NextInit = ExtractString(NextInit, InitBuffer,FALSE);
NextExit = ExtractString(NextExit, ExitBuffer,FALSE);
NextPrefix = ExtractString(NextPrefix, PrefixBuffer,FALSE);
}
else
{
if(DialNode -> Entry)
{
NextNumber = ExtractString(DialNode -> Entry -> Number,NumberBuffer,TRUE);
NextInit = ExtractString(DialNode -> Entry -> Config . ModemInit,InitBuffer,FALSE);
NextExit = ExtractString(DialNode -> Entry -> Config . ModemExit,ExitBuffer,FALSE);
NextPrefix = ExtractString(DialNode -> Entry -> Config . DialPrefix,PrefixBuffer,FALSE);
}
else
{
NextNumber = ExtractString(DialNode -> VanillaNode . ln_Name,NumberBuffer,TRUE);
NextInit = ExtractString(Config . ModemInit,InitBuffer,FALSE);
NextExit = ExtractString(Config . ModemExit,ExitBuffer,FALSE);
NextPrefix = ExtractString(Config . DialPrefix,PrefixBuffer,FALSE);
}
}
/* If DialNode -> Entry is nonzero it has
* a configuration attached.
*/
if(DialNode -> Entry)
{
DialTimeout = DialNode -> Entry -> Config . DialTimeout;
DialRetries = DialNode -> Entry -> Config . DialRetries;
/* We will need to change the serial parameters
* in order to establish a connection.
*/
if(memcmp(&Config,&DialNode -> Entry -> Config,offsetof(struct Configuration,ModemInit)))
{
BYTE SameDevice = TRUE;
CopyMem(&DialNode -> Entry -> Config,&Config,offsetof(struct Configuration,ModemInit));
Config . SerBuffSize = DialNode -> Entry -> Config . SerBuffSize;
/* Any device name change? */
if(strcmp(PrivateConfig . SerialDevice,Config . SerialDevice))
SameDevice = FALSE;
else
{
/* Handshaking mode changed to RTS/CTS protocol? */
if((PrivateConfig . Handshaking != HANDSHAKING_RTSCTS && Config . Handshaking == HANDSHAKING_RTSCTS) || PrivateConfig . SerBuffSize != Config . SerBuffSize)
SameDevice = FALSE;
}
/* Stop any IO activity. */
ClearSerial();
/* No dramatic changes? Simply change the parameters. */
if(SameDevice)
{
/* Use new parameters... */
SetFlags(WriteRequest);
SetFlags(ReadRequest);
/* ...and set them. */
WriteRequest -> IOSer . io_Command = SDCMD_SETPARAMS;
DoIO(WriteRequest);
/* Restart read request. */
ReadRequest -> IOSer . io_Command = CMD_READ;
ReadRequest -> IOSer . io_Data = ReadBuffer;
ReadRequest -> IOSer . io_Length = 1;
SetSignal(0,SIG_SERIAL);
SendIO(ReadRequest);
}
else
{
UBYTE *Error;
DeleteSerial();
if(!(Error = CreateSerial()))
{
if(StripBuffer)
FreeVec(StripBuffer);
if(!(StripBuffer = (UBYTE *)AllocVec(Config . SerBuffSize,MEMF_ANY)))
Error = LocaleString(MSG_GLOBAL_NO_AUX_BUFFERS_TXT);
}
if(Error)
{
BlockWindow(PanelWindow);
MyEasyRequest(PanelWindow,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Error);
DeleteSerial();
ReleaseWindow(PanelWindow);
SerialSet = FALSE;
goto Quit;
}
else
{
if(SerialMessage)
{
MyEasyRequest(Window,LocaleString(MSG_GLOBAL_TERM_HAS_A_PROBLEM_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),SerialMessage);
SerialMessage = NULL;
}
}
}
if(!Terminated)
{
WaitTime(0,MILLION / 2);
SerWrite("\rAT\r",4);
WaitTime(0,MILLION / 2);
}
/* Don't reinitialize serial driver in ConfigSetup()! */
SerialSet = TRUE;
}
if(ExitString[0])
{
SerialCommand(ExitString);
WaitTime(0,MILLION / 2);
}
if(InitBuffer[0])
{
SerialCommand(InitBuffer);
WaitTime(0,MILLION / 2);
}
strcpy(ExitString,ExitBuffer);
PrintInfo(PanelWindow,0,DialNode -> Entry -> Name);
Say(LocaleString(MSG_DIALPANEL_NOW_CALLING_TXT),DialNode -> Entry -> Name);
strcpy(SomeBuffer,PrefixBuffer);
PrintInfo(PanelWindow,1,NumberBuffer);
strcat(SomeBuffer,NumberBuffer);
}
else
{
DialTimeout = Config . DialTimeout;
DialRetries = Config . DialRetries;
if(ExitString[0])
{
SerialCommand(ExitString);
WaitTime(0,MILLION / 2);
}
strcpy(ExitString,ExitBuffer);
PrintInfo(PanelWindow,0,LocaleString(MSG_GLOBAL_UNKNOWN_TXT));
Say(LocaleString(MSG_DIALPANEL_NOW_CALLING_TXT),NumberBuffer);
strcpy(SomeBuffer,PrefixBuffer);
PrintInfo(PanelWindow,1,NumberBuffer);
strcat(SomeBuffer,NumberBuffer);
}
if(DialNode -> VanillaNode . ln_Succ -> ln_Succ)
PrintInfo(PanelWindow,2,((struct PhoneNode *)DialNode -> VanillaNode . ln_Succ) -> Entry -> Name);
else
PrintInfo(PanelWindow,2,LocaleString(MSG_GLOBAL_NONE_TXT));
strcat(SomeBuffer,"\r");
PrintInfo(PanelWindow,7,LocaleString(MSG_DIALPANEL_DIALING_TXT));
/* Dial the number. */
SerialCommand(SomeBuffer);
/* Reset the signal. */
SetSignal(NULL,SIGBREAKF_CTRL_F);
while(!Terminated)
{
if(Dialing)
{
PrintInfo(PanelWindow,4,"%2ld:%02ld",DialTimeout / 60,DialTimeout % 60);
PrintInfo(PanelWindow,5,LocaleString(MSG_DIALPANEL_ATTEMPT_OF_TXT),DialAttempt + 1,DialRetries);
}
else
PrintInfo(PanelWindow,4,"%2ld:%02ld",RedialDelay / 60,RedialDelay % 60);
WaitTime(0,MILLION / 2);
/* The following commands are executed each second */
if((RunCount++) && !Terminated)
{
RunCount = 0;
/* Are we dialing or waiting? */
if(Dialing)
{
/* No chance, the dial timeout
* has elapsed and no connection
* was made.
*/
if(!(--DialTimeout))
{
PrintInfo(PanelWindow,7,LocaleString(MSG_DIALPANEL_DIAL_ATTEMPT_TIMEOUT_TXT));
Skip1: WaitTime(0,MILLION / 2);
SerWrite("\r",1);
WaitTime(0,MILLION / 2);
/* Did we dial all the numbers available? */
if(NextNumber)
goto Dial;
/* Is this one the last entry? */
if(DialNode -> VanillaNode . ln_Succ -> ln_Succ)
{
/* Proceed to the next entry. */
DialNode = (struct DialNode *)DialNode -> VanillaNode . ln_Succ;
goto Dial;
}
else
{
/* Is this one the last dial
* attempt to be made?
*/
if(++DialAttempt >= DialRetries)
{
PrintInfo(PanelWindow,7,LocaleString(MSG_DIALPANEL_MAXIMUM_NUMBER_OF_DIAL_RETRIES_TXT));
WakeUp(PanelWindow,TRUE);
WaitTime(2,0);
Say(LocaleString(MSG_DIALPANEL_MAXIMUM_NUMBER_OF_DIAL_RETRIES_TXT));
Terminated = TRUE;
}
else
{
/* Get the first list entry. */
DialNode = (struct PhoneNode *)DialList -> lh_Head;
/* Get the redial delay. */
if(DialNode -> Entry)
RedialDelay = 10 * DialNode -> Entry -> Config . RedialDelay;
else
RedialDelay = 10 * Config . RedialDelay;
/* No redial delay? Restart dialing... */
if(!RedialDelay)
{
WaitTime(1,0);
goto Dial;
}
else
{
/* Go into redial delay. */
PrintInfo(PanelWindow,7,LocaleString(MSG_DIALPANEL_REDIAL_DELAY_TXT));
Dialing = FALSE;
Say(LocaleString(MSG_DIALPANEL_WAITING_TXT));
}
}
}
}
}
else
{
if(!(--RedialDelay))
{
/* Get the first list entry. */
Skip2: DialNode = (struct PhoneNode *)DialList -> lh_Head;
/* We are once again dialing. */
Dialing = TRUE;
goto Dial;
}
}
}
/* Handle serial data flow. */
HandleSerial();
/* Something has changed in the flow
* info structure.
*/
if(FlowInfo . Changed)
{
/* We had a connect and the
* baud rate has been transferred.
*/
if(BaudWasPending && !BaudPending)
{
ULONG Value;
if(Value = atol(BaudBuffer))
{
if(DialNode -> Entry)
CopyMem(&DialNode -> Entry -> Config,&Config,sizeof(struct Configuration));
Config . BaudRate = Value;
}
goto ConnectIt;
}
/* Current number is busy. */
if(FlowInfo . Busy || FlowInfo . NoCarrier)
{
FlowInit();
FullCheck = TRUE;
FlowInfo . Busy = FALSE;
FlowInfo . NoCarrier = FALSE;
FlowInfo . Changed = FALSE;
if(Dialing)
{
PrintInfo(PanelWindow,7,LocaleString(MSG_DIALPANEL_LINE_IS_BUSY_TXT));
Say(LocaleString(MSG_DIALPANEL_LINE_IS_BUSY_TXT));
WaitTime(1,0);
goto Skip1;
}
}
/* Line does not feature a dialtone. */
if(FlowInfo . NoDialTone)
{
FlowInit();
PrintInfo(PanelWindow,7,LocaleString(MSG_DIALPANEL_NO_DIALTONE_TXT));
WakeUp(PanelWindow,FALSE);
WaitTime(1,0);
Say(LocaleString(MSG_DIALPANEL_NO_DIALTONE_TXT));
Terminated = TRUE;
}
/* Somebody tries to call us. */
if(FlowInfo . Ring && !Terminated)
{
FlowInit();
PrintInfo(PanelWindow,7,LocaleString(MSG_GLOBAL_INCOMING_CALL_TXT));
WakeUp(PanelWindow,TRUE);
WaitTime(1,0);
Say(LocaleString(MSG_GLOBAL_INCOMING_CALL_TXT));
Terminated = TRUE;
}
/* Somebody's talking. */
if(FlowInfo . Voice && !Terminated)
{
FlowInit();
PrintInfo(PanelWindow,7,LocaleString(MSG_DIALPANEL_INCOMING_VOICE_CALL_TXT));
WakeUp(PanelWindow,TRUE);
WaitTime(1,0);
Say(LocaleString(MSG_DIALPANEL_INCOMING_VOICE_CALL_TXT));
Terminated = TRUE;
}
/* We got a connect. */
if(FlowInfo . Connect && !Terminated)
{
FlowInfo . Connect = FALSE;
FlowInfo . Changed = FALSE;
/* Auto-baud feature enabled?
* If yes, wait for the number.
*/
if(BaudPending)
{
if(Config . ConnectAutoBaud)
BaudWasPending = TRUE;
else
BaudPending = FALSE;
}
/* Seems that we've received
* a number.
*/
ConnectIt: if(!BaudPending)
{
/* Install the new configuration. */
if(!BaudWasPending)
{
if(DialNode -> Entry)
CopyMem(&DialNode -> Entry -> Config,&Config,sizeof(struct Configuration));
}
/* Convert the baud rate. */
if(BaudBuffer[0])
{
LONG TestRate = atol(BaudBuffer);
if(TestRate >= 110)
Config . BaudRate = TestRate;
}
/* Reset the scanner. */
FlowInit();
/* Copy the remaining data. */
if(DialNode -> Entry)
{
SelectTime(DialNode -> Entry);
ChosenEntry = DialNode -> Entry;
CurrentPay = 0;
SendStartup = TRUE;
strcpy(Password,DialNode -> Entry -> Password);
strcpy(UserName,DialNode -> Entry -> UserName);
}
else
{
CurrentPay = 0;
ChosenEntry = NULL;
Password[0] = 0;
UserName[0] = 0;
SendStartup = FALSE;
}
/* We are now online. */
Online = TRUE;
Terminated = TRUE;
/* Add another logfile entry. */
if(DialNode -> Entry)
LogAction(LocaleString(MSG_DIALPANEL_CONNECTED_TO_1_TXT),DialNode -> Entry -> Name,NumberBuffer);
else
LogAction(LocaleString(MSG_DIALPANEL_CONNECTED_TO_2_TXT),NumberBuffer);
/* Open auto-capture file if necessary. */
if(Config . ConnectAutoCapture && Config . CapturePath[0])
{
UBYTE SharedBuffer[256],Name[50],Date[20];
struct DateTime DateTime;
DateStamp(&DateTime . dat_Stamp);
DateTime . dat_Format = FORMAT_DOS;
DateTime . dat_Flags = 0;
DateTime . dat_StrDay = NULL;
DateTime . dat_StrDate = Date;
DateTime . dat_StrTime = NULL;
strcpy(SharedBuffer,Config . CapturePath);
if(DateToStr(&DateTime))
{
if(DialNode -> Entry)
{
WORD i;
strcpy(Name,DialNode -> Entry -> Name);
for(i = 0 ; i < strlen(Name) ; i++)
{
if(Name[i] == ' ')
Name[i] = '_';
}
}
else
strcpy(Name,LocaleString(MSG_DIALPANEL_CAPTURE_NAME_TXT));
strcat(Name,"_");
strcat(Name,Date);
if(AddPart(SharedBuffer,Name,256))
{
struct MenuItem *Item;
Item = FindThisItem(MEN_CAPTUREDISK);
Item -> Flags &= ~CHECKED;
if(FileCapture)
{
BufferClose(FileCapture);
if(!GetFileSize(CaptureName))
DeleteFile(CaptureName);
else
SetProtection(CaptureName,FIBF_EXECUTE);
}
if(FileCapture = BufferOpen(SharedBuffer,"a"))
{
Item -> Flags |= CHECKED;
strcpy(CaptureName,SharedBuffer);
}
}
}
}
/* Remove the node from the
* dialing list.
*/
if(DialNode -> Entry)
RemoveDialNode(DialNode);
Remove(&DialNode -> VanillaNode);
FreeVec(DialNode);
/* Wake the user up. */
PrintInfo(PanelWindow,7,LocaleString(MSG_DIALPANEL_CONNECTION_ESTABLISHED_TXT));
WakeUp(PanelWindow,TRUE);
if(Config . BackupConfig)
{
if(!BackupConfig)
{
if(BackupConfig = (struct Configuration *)AllocVec(sizeof(struct Configuration),MEMF_ANY))
memcpy(BackupConfig,&PrivateConfig,sizeof(struct Configuration));
}
}
Say(LocaleString(MSG_DIALPANEL_CONNECTION_ESTABLISHED_TXT));
/* Don't process any data until the screen
* is set up correctly.
*/
Blocking = TRUE;
/* Perform system initialization. */
ConfigSetup();
}
}
}
/* Look for the hotkey. */
if(SetSignal(NULL,NULL) & SIGBREAKF_CTRL_F)
{
SetSignal(NULL,SIGBREAKF_CTRL_F);
/* Are we dialing or waiting? */
if(Dialing)
{
DialTimeout = 0;
goto Skip1;
}
else
{
RedialDelay = 0;
goto Skip2;
}
}
/* Pick up the window input. */
while(!Terminated && (Massage = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort)))
{
Class = Massage -> Class;
Code = Massage -> Code;
Gadget = (struct Gadget *)Massage -> IAddress;
GT_ReplyIMsg(Massage);
if(Class == IDCMP_VANILLAKEY)
{
if(Code == ' ')
{
Class = IDCMP_GADGETUP;
Code = 0;
Gadget = GadgetArray[GAD_SKIP];
}
else
KeySelect(GadgetArray,GAD_ABORT,Code,PanelWindow,&Gadget,&Class,&Code);
}
/* Close the window, hang up the line. */
if(Class == IDCMP_CLOSEWINDOW)
{
Class = IDCMP_GADGETUP;
Gadget = GadgetArray[GAD_ABORT];
Result = TRUE;
}
if(Class == IDCMP_GADGETUP)
{
switch(Gadget -> GadgetID)
{
/* Don't proceed to the next number in the buffer! */
case GAD_REMOVE:NextNumber = NULL;
if(Dialing)
{
struct PhoneNode *NextNode = NULL;
/* Is there another entry in the list? */
if(DialNode -> VanillaNode . ln_Succ -> ln_Succ)
NextNode = (struct PhoneNode *)DialNode -> VanillaNode . ln_Succ;
else
{
/* No, there isn't; do we have a list with
* at least two entries in it?
*/
if(DialList -> lh_Head -> ln_Succ -> ln_Succ)
{
/* There is just a single entry
* available, check for dial retry
* limit.
*/
if(++DialAttempt >= DialRetries)
{
PrintInfo(PanelWindow,7,LocaleString(MSG_DIALPANEL_MAXIMUM_NUMBER_OF_DIAL_RETRIES_TXT));
WakeUp(PanelWindow,TRUE);
WaitTime(1,0);
Say(LocaleString(MSG_DIALPANEL_MAXIMUM_NUMBER_OF_DIAL_RETRIES_TXT));
Terminated = TRUE;
}
else
{
/* Grab first list entry and continue. */
NextNode = (struct PhoneNode *)DialList -> lh_Head;
}
}
else
{
Terminated = TRUE;
PrintInfo(PanelWindow,7,LocaleString(MSG_DIALPANEL_DIALING_LIST_IS_EMPTY_TXT));
WaitTime(1,0);
}
}
DialTimeout = 0;
WaitTime(0,MILLION / 2);
SerWrite("\r",1);
WaitTime(0,MILLION / 2);
/* Remove dial entry from list. */
if(DialNode -> Entry)
RemoveDialNode(DialNode);
Remove(&DialNode -> VanillaNode);
FreeVec(DialNode);
/* Is there an entry to proceed with? */
if(NextNode)
{
DialNode = NextNode;
goto Dial;
}
}
else
{
struct PhoneNode *LastNode;
/* We are to leave the redial delay loop,
* are there at least two entries in
* the list?
*/
if(!DialList -> lh_Head -> ln_Succ -> ln_Succ)
{
/* No, there is just a single entry in
* the list.
*/
Terminated = TRUE;
PrintInfo(PanelWindow,7,LocaleString(MSG_DIALPANEL_DIALING_LIST_IS_EMPTY_TXT));
WaitTime(0,MILLION / 2);
SerWrite("\r",1);
WaitTime(2,MILLION / 2);
}
/* Remove last dial entry from list. */
LastNode = (struct PhoneNode *)DialList -> lh_TailPred;
if(LastNode -> Entry)
RemoveDialNode(LastNode);
Remove(&LastNode -> VanillaNode);
FreeVec(LastNode);
/* Get back to first list entry. */
if(!Terminated)
{
RedialDelay = 0;
goto Skip2;
}
}
break;
case GAD_SKIP: if(Dialing)
{
DialTimeout = 0;
goto Skip1;
}
else
{
RedialDelay = 0;
goto Skip2;
}
/* Forced online,
* install new configuration
* first.
*/
case GAD_ONLINE:if(DialNode -> Entry)
CopyMem(&DialNode -> Entry -> Config,&Config,sizeof(struct Configuration));
/* Copy the remaining information. */
if(DialNode -> Entry)
{
SelectTime(DialNode -> Entry);
ChosenEntry = DialNode -> Entry;
CurrentPay = 0;
SendStartup = TRUE;
strcpy(Password,DialNode -> Entry -> Password);
strcpy(UserName,DialNode -> Entry -> UserName);
}
else
{
CurrentPay = 0;
ChosenEntry = NULL;
Password[0] = 0;
UserName[0] = 0;
SendStartup = FALSE;
}
/* We are now online. */
Online = TRUE;
Terminated = TRUE;
/* Add a new log action. */
if(DialNode -> Entry)
LogAction(LocaleString(MSG_DIALPANEL_CONNECTED_TO_1_TXT),DialNode -> Entry -> Name,NumberBuffer);
else
LogAction(LocaleString(MSG_DIALPANEL_CONNECTED_TO_2_TXT),NumberBuffer);
/* Open auto-capture file. */
if(Config . ConnectAutoCapture && Config . CapturePath[0])
{
UBYTE SharedBuffer[256],Name[50],Date[20];
struct DateTime DateTime;
DateStamp(&DateTime . dat_Stamp);
DateTime . dat_Format = FORMAT_DOS;
DateTime . dat_Flags = 0;
DateTime . dat_StrDay = NULL;
DateTime . dat_StrDate = Date;
DateTime . dat_StrTime = NULL;
strcpy(SharedBuffer,Config . CapturePath);
if(DateToStr(&DateTime))
{
if(DialNode -> Entry)
{
WORD i;
strcpy(Name,DialNode -> Entry -> Name);
for(i = 0 ; i < strlen(Name) ; i++)
{
if(Name[i] == ' ')
Name[i] = '_';
}
}
else
strcpy(Name,LocaleString(MSG_DIALPANEL_CAPTURE_NAME_TXT));
strcat(Name,"_");
strcat(Name,Date);
if(AddPart(SharedBuffer,Name,256))
{
struct MenuItem *Item;
Item = FindThisItem(MEN_CAPTUREDISK);
Item -> Flags &= ~CHECKED;
if(FileCapture)
{
BufferClose(FileCapture);
if(!GetFileSize(CaptureName))
DeleteFile(CaptureName);
else
SetProtection(CaptureName,FIBF_EXECUTE);
}
if(FileCapture = BufferOpen(SharedBuffer,"a"))
{
Item -> Flags |= CHECKED;
strcpy(CaptureName,SharedBuffer);
}
}
}
}
/* Remove node from
* dialing list and
* perform system
* setup.
*/
if(DialNode -> Entry)
RemoveDialNode(DialNode);
Remove(&DialNode -> VanillaNode);
FreeVec(DialNode);
if(Config . BackupConfig)
{
if(!BackupConfig)
{
if(BackupConfig = (struct Configuration *)AllocVec(sizeof(struct Configuration),MEMF_ANY))
memcpy(BackupConfig,&PrivateConfig,sizeof(struct Configuration));
}
}
Blocking = TRUE;
ConfigSetup();
break;
/* Abort the dialing process. */
case GAD_ABORT: Terminated = TRUE;
PrintInfo(PanelWindow,7,LocaleString(MSG_DIALPANEL_ABORTING_TXT));
WaitTime(0,MILLION / 2);
SerWrite("\r",1);
WaitTime(0,MILLION / 2);
break;
}
}
}
}
/* Are we perhaps not online? */
Quit: if(!Online)
{
/* Is the serial setup different? */
if(memcmp(&PrivateConfig,&Config,58))
{
/* Swap the serial data. */
swmem(&PrivateConfig,&Config,58);
/* Set up the old serial configuration. */
ConfigSetup();
/* Reinitialize... */
WaitTime(0,MILLION / 2);
SerWrite("\rAT\r",4);
WaitTime(0,MILLION / 2);
}
/* Do we have a valid modem exit string? */
if(ExitString[0])
{
SerialCommand(ExitString);
WaitTime(0,MILLION / 2);
}
}
/* Reset the scanner. */
FlowInit();
RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
PopWindow();
PositionX = PanelWindow -> LeftEdge;
PositionY = PanelWindow -> TopEdge;
CloseWindow(PanelWindow);
}
}
FreeGadgets(GadgetList);
/* We are done now, restart echoing serial */
Quiet = FALSE;
return(Result);
}